package cn.kt.controller.UserTeacher;

import cn.kt.common.pojo.PageObject;
import cn.kt.service.UserTeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;

@Controller
public class UserIndexController {

    @Autowired
    UserTeacherService userTeacherService;

    //教师列表页面
    @GetMapping("/teacher-list")
    public String showAllUser(
            Model model,
            @RequestParam(value = "pageCurrent",defaultValue = "1") Integer pageCurrent,
            @RequestParam(value = "user_name",defaultValue = "") String user_name,
            @RequestParam(value = "state",defaultValue = "") String stringState
    ){

        Integer state;
        if (!stringState.equals("") && !stringState.equals(null)
                && !stringState.equals("null") && !stringState.equals(" "))
        {
            state = Integer.valueOf(stringState);
        }else {
            state = null;
        }
        if (user_name.equals("") || user_name.equals("null") || user_name.equals(null) || user_name.equals(" ")){
            user_name = null;
        }
        PageObject po = userTeacherService.findAll(null,user_name,state,pageCurrent);

        model.addAttribute("pageObject",po);
        model.addAttribute("user",user_name);
        model.addAttribute("state",state);

        return "admin/index/teacher-list";
    }


}
